<template>
    <div>
        <Card>
            <div slot="title">
                <el-form
                    :inline="true"
                    :model="formInline"
                    class="demo-form-inline"
                >
                    <el-form-item label="订单号">
                        <el-input
                            v-model="formInline.orderNo"
                            placeholder="订单号"
                            size="medium"
                        ></el-input>
                    </el-form-item>

                    <el-form-item label="收货人">
                        <el-input
                            v-model="formInline.consignee"
                            placeholder="收货人"
                            size="medium"
                        ></el-input>
                    </el-form-item>

                    <el-form-item label="手机号">
                        <el-input
                            v-model="formInline.phone"
                            placeholder="手机号"
                            size="medium"
                        ></el-input>
                    </el-form-item>

                    <el-form-item label="订单状态">
                        <el-select
                            v-model="formInline.orderState"
                            placeholder="订单状态"
                            size="medium"
                        >
                            <el-option
                                label="已完成"
                                value="已完成"
                            ></el-option>
                            <el-option
                                label="已受理"
                                value="已受理"
                            ></el-option>
                            <el-option
                                label="派送中"
                                value="派送中"
                            ></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="选择时间">
                        <el-date-picker
                            v-model="formInline.date"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            class="time"
                            size="medium"
                        >
                        </el-date-picker>
                        <el-button type="primary" size="medium" @click="search"
                            >查询</el-button
                        >
                    </el-form-item>
                </el-form>
            </div>
            <div slot="content">
                <!-- 表格 -->
                <el-table :data="tableData" border style="width: 100%;">
                    <!-- 订单号 -->
                    <el-table-column
                        fixed
                        prop="orderNo"
                        label="订单号"
                        width="100"
                    >
                        <template slot-scope="scope">{{
                            scope.row.orderNo
                        }}</template>
                    </el-table-column>

                    <!-- 下单时间 -->
                    <el-table-column label="下单时间" width="160">
                        <template slot-scope="scope">{{
                            scope.row.orderTime | timer
                        }}</template>
                    </el-table-column>

                    <!-- 手机号 -->
                    <el-table-column label="手机号" width="120">
                        <template slot-scope="scope">{{
                            scope.row.phone
                        }}</template>
                    </el-table-column>

                    <!-- 收货人 -->
                    <el-table-column label="收货人" width="100">
                        <template slot-scope="scope">{{
                            scope.row.consignee
                        }}</template>
                    </el-table-column>

                    <!-- 配送地址 -->
                    <el-table-column label="配送地址" width="180">
                        <template slot-scope="scope">{{
                            scope.row.deliverAddress
                        }}</template>
                    </el-table-column>

                    <!-- 送达时间 -->
                    <el-table-column label="送达时间" width="160">
                        <template slot-scope="scope">{{
                            scope.row.deliveryTime | timer
                        }}</template>
                    </el-table-column>

                    <!-- 用户备注 -->
                    <el-table-column label="用户备注" width="120">
                        <template slot-scope="scope">{{
                            scope.row.remarks
                        }}</template>
                    </el-table-column>

                    <!-- 订单金额 -->
                    <el-table-column label="订单金额" width="100">
                        <template slot-scope="scope">{{
                            scope.row.orderAmount
                        }}</template>
                    </el-table-column>

                    <!-- 订单状态 -->
                    <el-table-column label="订单状态" width="100">
                        <template slot-scope="scope">{{
                            scope.row.orderState
                        }}</template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="100">
                        <template slot-scope="scope">
                            <el-button type="text" size="small"   @click="handleClick(scope.row)">查看</el-button>
                            
                        </template>
                    </el-table-column>
                </el-table>

                <!-- 分页器 -->
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
                >
                </el-pagination>


            </div>
        </Card>
    </div>
</template>

<script>
import Card from "@/components/Card.vue";
import { getOrderList, searchOrder } from "@/apis/order.js";
import moment from "moment";
export default {
    components: {
        Card,
    },
    data() {
        return {
            formInline: {
                orderNo: "",
                consignee: "",
                phone: "",
                orderState: "",
                date: [],
            },
            tableData: [],
            currentPage: 1, // 当前页数
            total: 0, //总页数
            pageSize: 5, //每页显示的条数


        };
    },
    methods: {
        handleClick(row){
            // 动态传参
            this.$router.push({
                path:"/order/order-info",
                query:{
                    row: JSON.stringify(row)
                }
            });
        },

        // 每条页数改变时会触发
        handleSizeChange(val) {
            this.total = val;
            this.getOrder();
        },
        // 当前页改变时触发
        handleCurrentChange(val) {
            this.currentPage = val;
            this.getOrder();
        },
        async getOrder() {
            let { total, data } = await getOrderList({
                currentPage: this.currentPage,
                pageSize: this.pageSize,
                orderNo: this.formInline.orderNo,
                consignee: this.formInline.consignee,
                phone: this.formInline.phone,
                orderState: this.formInline.orderState,
                date: JSON.stringify(
                    this.formInline.date == null ? [] : this.formInline.date
                ),
            });
            this.total = total;
            this.tableData = data;
        },
        // 查询按钮
        async search() {
            this.currentPage = 1;
            this.getOrder();
        },
    },
    created() {
        this.getOrder();
    },
    // 过滤 时间
    filters: {
        timer(val) {
            return moment(val).format("YYYY-MM-DD hh:mm");
        },
    },
};
</script>

<style lang="less" scoped>
.el-card {
    width: 100%;
    .demo-form-inline {
        margin-top: 10px;
        .el-form-item {
            margin-left: 5px;
            /deep/.el-input__inner {
                width: 200px;
            }
            .time {
                width: 400px;
            }
            .el-button {
                margin-left: 10px;
            }
        }
    }
}
.el-pagination {
    margin-top: 20px;
}
/deep/.el-table .cell {
    white-space: nowrap;
}

</style>